﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace XiaoGang.Soft.XGWMS.UI
{
    class CaptionButton:Label
    {
        public CaptionButton()
        {
            this.BackColor = Color.Transparent;
            this.ForeColor = Color.WhiteSmoke;
            this.Cursor = Cursors.Arrow;
        }

        private bool _IsActive = false;

        public bool IsActive
        {
            get { return _IsActive; }
            set 
            { 
                _IsActive = value;
                SetColor();
            }
        }

        private bool _IsSelect = false;

        public bool IsSelect
        {
            get { return _IsSelect; }
            set 
            { 
                _IsSelect = value;
                SetColor();
            }
        }

        private void SetColor()
        {
            if (IsSelect == true)
            {
                this.BackColor = Color.FromArgb(249, 249, 244);
                this.ForeColor = Color.Black;
            }
            else
            {
                if (IsActive == true)
                {
                    this.BackColor = Color.FromArgb(193, 210, 238);
                    this.ForeColor = Color.Black;
                }
                else
                {
                    this.BackColor = Color.Transparent;
                    this.ForeColor = Color.WhiteSmoke;
                }
            }
        }

        private void DrawBorder(Graphics g)
        {
            Pen pen = new Pen(Color.FromArgb(49, 106, 197));

            g.DrawRectangle(pen, 0, 0, Width - 1, Height - 1);

            pen.Dispose();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (IsActive == true || IsSelect == true)
            {
                DrawBorder(e.Graphics);
            }
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            IsSelect = true;
            Refresh();
            base.OnMouseDown(e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            IsSelect = false;
            Refresh();
            base.OnMouseUp(e);
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            IsActive = true;
            Refresh();
            base.OnMouseEnter(e);
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            IsActive = false;
            Refresh();
            base.OnMouseLeave(e);
        }
    }
}
